package com.corpdata.app.project.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.corpdata.core.base.AbstractBaseService;
import com.corpdata.system.org.entity.OrgUser;
import com.corpdata.app.project.dao.ProjectTeamMapper;
import com.corpdata.app.project.entity.ProjectInfo;
import com.corpdata.app.project.entity.ProjectTeam;
import com.corpdata.app.project.service.ProjectTeamService;
import com.corpdata.common.result.Result;
import com.corpdata.common.utils.CorpdataUtil;

/**
 * 楼盘管理团队
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-14 10:54:27
 */
@Service
@Transactional
public class ProjectTeamServiceImpl extends AbstractBaseService<ProjectTeam> implements ProjectTeamService {
	
	@Autowired
	private ProjectTeamMapper projectTeamMapper;
	
	public Result insert(String projectId,String teamUserids,String role,int type) {
		Result ret=null;
		String[] Userids=teamUserids.split(",");
		for(String userid:Userids){
			ProjectTeam record=new ProjectTeam();
			record.setId(CorpdataUtil.getUUID());
			OrgUser orgUser=new OrgUser();
			orgUser.setId(userid);
			record.setUser(orgUser);
			record.setTeamRole(role);
			record.setTeamType(type);
			ProjectInfo info=new ProjectInfo();
			info.setId(projectId);
			record.setProject(info);
			ret=super.save(record);
		}
		return ret;
	}
	
	public List<ProjectTeam> selectAll(String projectId,String userId){
		Map<String,Object> params=new HashMap<String,Object>();
		
		if(projectId!=null&&!"".equals(projectId)){
			params.put("projectId", projectId);
		}
		if(userId!=null&&!"".equals(userId)){
			params.put("userId", userId);
		}
		
		return projectTeamMapper.selectAll(params);
	}
	
	
}
